/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.market.web.EJB;

import com.market.web.model.Customer;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author ps
 */
@Stateless
public class CustomerFacade extends AbstractFacade<Customer> {
    @PersistenceContext(unitName = "onlineMarketPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    
    public Customer getCustomerByEmail(String email) {
        Query createNamedQuery = getEntityManager().createNamedQuery("Customer.findByEmail");

        createNamedQuery.setParameter("email", email);

        if (createNamedQuery.getResultList().size() > 0) {
            return (Customer) createNamedQuery.getSingleResult();
        }
        else {
            return null;
        }
    }
    
    public CustomerFacade() {
        super(Customer.class);
    }
    
}
